﻿using HotelManager.Models;
using HotelManager.Models.Params;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HotelManager.Service
{
    public class RoleService: IRoleService
    {
        private readonly HttpRestClient client;
        public RoleService(HttpRestClient client)
        {
            this.client = client;
        }
        public async Task<List<RoleData>> GetAllAsync()
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Get;
            request.Route = $"api/Role/List";
            return await client.ExecuteAsync<List<RoleData>>(request);
        }
        public async Task<ResultData<string>> AddAsync(string roleName)
        {
            BaseRequest request = new BaseRequest();
            RoleNameData roleNameBody = new RoleNameData() { roleName = roleName };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/Role/Add";
            request.Parameter = roleNameBody;
            return await client.ExecutePostAsync<ResultData<string>>(request);
        }
        public ResultData<string> Update(RoleData roleData)
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/Role/Update";
            request.Parameter = roleData;
            return client.ExecuteSync<ResultData<string>>(request);
        }
        public async Task<RoleData> GetFirstOrDefaultAsync(int roleId)
        {
            BaseRequest request = new BaseRequest();
            RoleIdData roleIdBody = new RoleIdData() { roleId = roleId };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/Role/GetOne";
            request.Parameter = roleIdBody;
            return await client.ExecutePostAsync<RoleData>(request);
        }
        public async Task<ResultData<string>> DeleteAsync(int roleId)
        {
            BaseRequest request = new BaseRequest();
            RoleIdData roleIdBody = new RoleIdData() { roleId = roleId };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/Role/Delete";
            request.Parameter = roleIdBody;
            return await client.ExecutePostAsync<ResultData<string>>(request);
        }
    }
}
